package com.petshop.transactionrecords.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.petshop.common.annotation.Log;
import com.petshop.common.core.controller.BaseController;
import com.petshop.common.core.domain.AjaxResult;
import com.petshop.common.enums.BusinessType;
import com.petshop.transactionrecords.domain.PetTransactionrecords;
import com.petshop.transactionrecords.service.IPetTransactionrecordsService;
import com.petshop.common.utils.poi.ExcelUtil;
import com.petshop.common.core.page.TableDataInfo;

/**
 * 交易记录Controller
 *
 * @author ruoyi
 * @date 2024-09-12
 */
@RestController
@RequestMapping("/transactionrecords/transactionrecords")
public class PetTransactionrecordsController extends BaseController
{
    @Autowired
    private IPetTransactionrecordsService petTransactionrecordsService;

    /**
     * 查询交易记录列表
     */
    @PreAuthorize("@ss.hasPermi('transactionrecords:transactionrecords:list')")
    @GetMapping("/list")
    public TableDataInfo list(PetTransactionrecords petTransactionrecords)
    {
        startPage();
        List<PetTransactionrecords> list = petTransactionrecordsService.selectPetTransactionrecordsList(petTransactionrecords);
        return getDataTable(list);
    }

    /**
     * 导出交易记录列表
     */
    @PreAuthorize("@ss.hasPermi('transactionrecords:transactionrecords:export')")
    @Log(title = "交易记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PetTransactionrecords petTransactionrecords)
    {
        List<PetTransactionrecords> list = petTransactionrecordsService.selectPetTransactionrecordsList(petTransactionrecords);
        ExcelUtil<PetTransactionrecords> util = new ExcelUtil<PetTransactionrecords>(PetTransactionrecords.class);
        util.exportExcel(response, list, "交易记录数据");
    }

    /**
     * 获取交易记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('transactionrecords:transactionrecords:query')")
    @GetMapping(value = "/{transactionID}")
    public AjaxResult getInfo(@PathVariable("transactionID") Long transactionID)
    {
        return success(petTransactionrecordsService.selectPetTransactionrecordsByTransactionID(transactionID));
    }

    /**
     * 新增交易记录
     */
    @PreAuthorize("@ss.hasPermi('transactionrecords:transactionrecords:add')")
    @Log(title = "交易记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PetTransactionrecords petTransactionrecords)
    {
        return toAjax(petTransactionrecordsService.insertPetTransactionrecords(petTransactionrecords));
    }

    /**
     * 修改交易记录
     */
    @PreAuthorize("@ss.hasPermi('transactionrecords:transactionrecords:edit')")
    @Log(title = "交易记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PetTransactionrecords petTransactionrecords)
    {
        return toAjax(petTransactionrecordsService.updatePetTransactionrecords(petTransactionrecords));
    }

    /**
     * 删除交易记录
     */
    @PreAuthorize("@ss.hasPermi('transactionrecords:transactionrecords:remove')")
    @Log(title = "交易记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{transactionIDs}")
    public AjaxResult remove(@PathVariable Long[] transactionIDs)
    {
        return toAjax(petTransactionrecordsService.deletePetTransactionrecordsByTransactionIDs(transactionIDs));
    }
}
